package com.example.yuwei.registerlogin_system;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class webActivity extends AppCompatActivity {
    private WebView web;
    private String agreeMent1 = "http://";
    private String agreeMent2 = "https://";
    private  String baiduUrl = "http://www.baidu.com";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        init();
    }

    public void back(View view) {
        web.goBack();
        //webActivity.this.finish();
    }

    public void init() {
        web = findViewById(R.id.web);
        web.getSettings().setJavaScriptEnabled(true);
        web.setWebViewClient(new WebViewClient() {
                                 @Override
                                 public boolean shouldOverrideUrlLoading(WebView view, String url) {
                                     if (url == null) {
                                         return false;
                                     }
                                     try {
                                         if (!url.startsWith(agreeMent1) && !url.startsWith(agreeMent2)) {
                                             startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                                             return true;
                                         }
                                     } catch (Exception e) {
                                         return false;
                                     }
                                     web.loadUrl(url);
                                     return true;
                                 }
                             }
        );
        web.loadUrl(baiduUrl);
    }
}
